package com.soul.dubbo.api.db;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.soul.dubbo.api.mapper.QuestionsMapper;
import com.soul.model.db.Question;
import com.soul.model.mongo.Questions;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * @author mdoya
 * @version 1.0
 * @description:
 */
@Slf4j
@DubboService
public class QuestionsImpl implements QuestionsApi {

    @Autowired
    private QuestionsMapper questionsMapper;

    /**
     * 设置陌生人问题 - 保存(更新对象)
     *
     * @param question
     * @return
     */
    @Override
    public void UpdateUserQuestions(Question question) {
        LambdaQueryWrapper<Question> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(Question::getUserId,question.getUserId());
        Question questions = questionsMapper.selectOne(lambdaQueryWrapper);
        if (questions != null){
            question.setId(questions.getId());
            questionsMapper.updateById(question);
            return;
        }
        questionsMapper.insert(question);
    }

    @Override
    public Question findQuestionById(Long beautyUserId) {
        LambdaQueryWrapper<Question> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(beautyUserId != null,Question::getUserId,beautyUserId);
        return questionsMapper.selectOne(lambdaQueryWrapper);
    }
}
